//
//  ZYUserInfoViewModel.m
//  YiLin
//
//  Created by Zyark on 2018/6/14.
//  Copyright © 2018年 Zyark. All rights reserved.
//

#import "ZYUserInfoViewModel.h"
#import "AFNetWorkUtils.h"
#import "ZYUser.h"

@implementation ZYUserInfoViewModel
-(RACCommand *)userInfoCommand{
    if(!_userInfoCommand){
        _userInfoCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
            NSString *url = [NSString stringWithFormat:@"%@%@",ZYAPI_BASE_URL,ZYAPI_GET_USER_INFO_URL];
            NSDictionary *params = @{@"ssid":[ZYConfig loginToken]};
            return [[AFNetWorkUtils racGETWithURL:url params:params] map:^id(id value) {
                NSDictionary *data = value;
                ZYUser *user = [ZYUser modelWithJSON:[data objectForKey:@"result"]];
                [ZYConfig saveUserInfo:user];
                return user;
            }];
        }];
    }
    return _userInfoCommand;
}
@end
